<?php

  namespace common\models;


class AQ extends \yii\db\ActiveQuery
{
    const ACTIVE = 0;
    const DELETED = 1;
/*    public function active()
    {
        $this->andWhere(['deleted'=>self::DELETED_ACTIVE]);
        return $this;
    }*/
/*
    public function init()
    {
      parent::init();
      //var_dump($this);
      if(\Yii::$app->controller->module->id == 'admin'){

      }else{
        //\yii\db\ActiveRecord
        $modelClass = $this->modelClass;
        $tableName = $modelClass::tableName();
        //var_dump($tableName);
        $this->andWhere([$tableName.'.deleted'=>self::ACTIVE]);
      }
    }
  */
  public function active(){
    return $this->status(AQ::ACTIVE);
  }

  public function deleted(){
    return $this->status(AQ::DELETED);
  }

  private  function status($d){
    $model = new $this->modelClass();
    $this->alias($model->a);
    //app-backend
    $this->andFilterWhere([$model->a.'.deleted'=>$d]);
    return $this;
  }

  public function all($db = null)
  {
    return parent::all($db);
  }


  public function one($db = null)
  {
    return parent::one($db);
  }

}